$(function(){
	getMenu();

	$('.cart-c-title-icon').click(function() {
        	$('.cart-c').animate({ right: "-450px" }, function() {
        });
    });
    resetCartPosition();
    $(window).resize(function(){
    	resetCartPosition();
    });
})

function resetCartPosition() {
    $('.cart-c').height(Number($(window).height())-10);
    $('.cart-c-box').height(Number($(window).height()) - 60);
}

function getMenu(){
	$.ajax({
		type: "post",
		url: "Admin/Menu/getMenu",
		async: true,
		dataType:'json',
		success: function(data) {
			if(data.status) {
				var t=JSON.parse(data.v);
				tree = $('#treeview-checkable').treeview({
		        data: t,
		        showIcon: false,
		        showCheckbox: false,
		        selectedBackColor: '#0F7CE0',
		        selectedColor: '#fff',
		        showTags: true,
		        // color:'#0F7CE0',
		        levels: 2,
		        // backColor:'#0F7CE0',
		        nodeUnselected: function(event, node) {

		        }
		    });
			} else {
				window.parent.topMessagePrompt('error',ret.msg);
			}
		}
	});
	
}


function delMenu(obj){
	swal({
		title: "请确认",
		text: '确认删除该菜单？',
		type: "warning",
		showCancelButton: true,
		closeOnConfirm: true,
		confirmButtonText: "确定",
		cancelButtonText: '取消',
		confirmButtonColor: "#ec6c62"
	}, function(isConfirm) {
		if(isConfirm) {
			$.ajax({
				type: "post",
				url: "Admin/Menu/delete",
				async: true,
				dataType:'json',
				data:{
					menu_id:$(obj).attr('data-id')
				},
				success: function(data) {
					if(data.status) {
						getMenu();
						window.parent.topMessagePrompt('success',data.msg);
					} else {
						window.parent.topMessagePrompt('error',data.msg);
					}
				}
			});
		}
	});
	
}



var editMenu = function(obj) {
	$('.cart-c').find('iframe').attr('src',getRootPath()+'/Admin/Menu/edit/'+$(obj).attr('data-id'));
	$('.cart-c .cart-c-title label').html('菜单编辑');
    $('.cart-c').animate({ right: "0px" });
};
var addMenu = function(obj) {
	$('.cart-c').find('iframe').attr('src',getRootPath()+'/Admin/Menu/edit/0/'+$(obj).attr('data-id'));
	$('.cart-c .cart-c-title label').html('菜单新增');
    $('.cart-c').animate({ right: "0px" });
};